package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.system.domain.Goods;
import com.ruoyi.system.mapper.OrderDetailsMapper;
import com.ruoyi.system.domain.OrderDetails;
import com.ruoyi.system.service.IOrderDetailsService;

/**
 * 订单详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-23
 */
@Service
public class OrderDetailsServiceImpl implements IOrderDetailsService 
{
    @Autowired
    private OrderDetailsMapper orderDetailsMapper;

    /**
     * 查询订单详情
     * 
     * @param orderDetailsID 订单详情主键
     * @return 订单详情
     */
    @Override
    public List<Goods> selectOrderDetailsByOrderDetailsID(Long orderDetailsID)
    {
        return orderDetailsMapper.selectOrderDetailsByOrderDetailsID(orderDetailsID);
    }

    /**
     * 查询订单详情列表
     * 
     * @param orderDetails 订单详情
     * @return 订单详情
     */
    @Override
    public List<OrderDetails> selectOrderDetailsList(OrderDetails orderDetails)
    {
        return orderDetailsMapper.selectOrderDetailsList(orderDetails);
    }

    /**
     * 新增订单详情
     * 
     * @param orderDetails 订单详情
     * @return 结果
     */
    @Transactional
    @Override
    public int insertOrderDetails(OrderDetails orderDetails)
    {
        return orderDetailsMapper.insertOrderDetails(orderDetails);
    }

    /**
     * 修改订单详情
     * 
     * @param orderDetails 订单详情
     * @return 结果
     */
    @Transactional
    @Override
    public int updateOrderDetails(OrderDetails orderDetails)
    {
        return orderDetailsMapper.updateOrderDetails(orderDetails);
    }

    /**
     * 批量删除订单详情
     * 
     * @param orderDetailsIDs 需要删除的订单详情主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteOrderDetailsByOrderDetailsIDs(Long[] orderDetailsIDs)
    {
        orderDetailsMapper.deleteGoodsByGoodIDs(orderDetailsIDs);
        return orderDetailsMapper.deleteOrderDetailsByOrderDetailsIDs(orderDetailsIDs);
    }

    /**
     * 删除订单详情信息
     * 
     * @param orderDetailsID 订单详情主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteOrderDetailsByOrderDetailsID(Long orderDetailsID)
    {
        orderDetailsMapper.deleteGoodsByGoodID(orderDetailsID);
        return orderDetailsMapper.deleteOrderDetailsByOrderDetailsID(orderDetailsID);
    }

    /**
     * 新增商品信息
     * 
     * @param orderDetails 订单详情对象
     */
    public void insertGoods(OrderDetails orderDetails)
    {
//        List<Goods> goodsList = orderDetails.getGoodsList();
//        Long orderDetailsID = orderDetails.getOrderDetailsID();
//        if (StringUtils.isNotNull(goodsList))
//        {
//            List<Goods> list = new ArrayList<Goods>();
//            for (Goods goods : goodsList)
//            {
//                goods.setGoodID(orderDetailsID);
//                list.add(goods);
//            }
//            if (list.size() > 0)
//            {
//                orderDetailsMapper.batchGoods(list);
//            }
//        }
    }
}
